home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-09-02 | 3.3 KB | 122 lines | [TEXT/MPS ] |
- { If you have any private types, uncomment the following line and add them }
- { TYPE }
-
- { Add implementations of your methods here }
-
- {The need for the following wait loop shows
- that statements following speech
- can happen concurrently, that is,
- are immediately executed during speech!
- For example, don't want to dispose his speech while the speaker is speaking!}
-
- PROCEDURE TSpeaker.WaitTilSpeechDone;
- var delayLen: LONGINT;
- begin
- while (NOT (SpeechBusy = 0)) do
- Delay(15, delayLen);
- end;
-
- FUNCTION TSpeaker.GetChannel:SpeechChannel;
- begin
- GetChannel:= fChannel;
- end;
-
- PROCEDURE TSpeaker.SetChannel(tc:SpeechChannel);
- begin
- fChannel:=tc;
- end;
-
- {Liked the deep voice of Boris, most like Schwartznegger's, NumberOfVoice=6:}
- PROCEDURE TSpeaker.ISpeaker(NumberOfVoice: Integer);
- var response : LONGINT;
- voiceCount:integer;
- theChannel: SpeechChannel;
- myErr: OSErr;
- theVoiceSpecPtr: VoiceSpecPtr;
- theVoiceSpec: VoiceSpec;
- begin
-
- {Following are speech commands,
- Put speech.p in Lab 7 folder,
- so PMake would see it without too much auxiliary scripting:}
-
- myErr := Gestalt(gestaltSpeechAttr, response ) ;
- if ((myErr <> noErr) or ((response=1) and
- (1 < gestaltSpeechMgrPresent))) then HALT;
-
- {Some sort of initialization needed even if not do loop of all:}
- myErr := CountVoices (voiceCount);
-
- if (myErr <> noErr) then HALT;
-
-
- if (NumberOfVoice<=voiceCount) then
- begin
- {Type transfer from generic pointer:}
- theVoiceSpecPtr := VoiceSpecPtr(@theVoiceSpec);
-
- {theVoiceSpecPtr is not var parm, so address value input,pass by address?}
- myErr := GetIndVoice (NumberOfVoice, theVoiceSpecPtr);
- if (myErr <> noErr) then HALT;
- myErr := NewSpeechChannel (theVoiceSpecPtr, theChannel);
- if (myErr <> noErr) then HALT;
- SetChannel(theChannel);
- end
- else
- begin
- HALT;
- end;
- end;
-
- PROCEDURE TSpeaker.Free;OVERRIDE;
- var myErr: OSErr;
- BEGIN
- WaitTilSpeechDone;
- myErr := DisposeSpeechChannel (fChannel);
- if (myErr <> noErr) then HALT;
- Dispose (SELF);
- END;
-
- {
- Comment on string lengths:
- Pasted from Spinside mac
- Toolbox utilities:
- String 'STR ' m bytes The string (1-byte length
- followed by the characters)
- THE MEMORY MANAGER
- Str255 = STRING[255];
- My remarks (PMS):
- 8bits specify 2^8=256 possibilities (less one possibility of string 0 length) or 255
- }
- PROCEDURE TSpeaker.SpeakStr( ToSayString: Str255);
- var textlen: LONGINT;
- myErr: OSErr;
- theTextPtr:Ptr;
- begin
-
- {Note: @ToSayString= @ToSayString[0] would tell length of text, since ToSayString:Str255,
- so we use @ToSayString[1] to start reading where we want to below:}
- theTextPtr:=Ptr(@ToSayString[1]);
-
- {Since we started reading at the right byte, we have the expected text length:}
- textlen:=Ord4(LENGTH(ToSayString));
-
- {OK now we have set up and it can speak:}
- myErr := SpeakText (GetChannel,theTextPtr,textlen);
- if (myErr <> noErr) then HALT;
-
- end;
-
- PROCEDURE TSpeaker.SpeakTxt(theTextHdl:Handle);
- var textlen: LONGINT;
- myErr: OSErr;
- theTextPtr:Ptr;
- begin
- textlen := GetHandleSize(theTextHdl);
- theTextPtr:= theTextHdl^;
-
- {OK now we have set up and it can speak:}
- myErr := SpeakText (GetChannel,theTextPtr,textlen);
- if (myErr <> noErr) then HALT;
- end;
-